package net.lqy.aipan.exception;

import lombok.extern.slf4j.Slf4j;
import net.lqy.aipan.util.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @title: CustomException
 * @Author lqy
 * @Date: 2025-05-30 12:24
 * @Version 1.0
 */
@Slf4j
@ControllerAdvice
public class CustomExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public JsonData handler(Exception e) {
        if (e instanceof BizException bizException) {
            log.error("[业务异常]{}", e);
            return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
        } else {
            log.error("[系统异常]{}", e);
            return JsonData.buildError("系统异常");
        }
    }
}
